#include"graphics.h"
extern char *str2;
void judge(char *str,MYSQL mysql,MYSQL *connection);
void talker_sql(char *str)
{
MYSQL mysql,*connection;
mysql_init(&mysql);

connection=mysql_real_connect(&mysql,"localhost","wuser","wuser","wang",0,0,0);
if(connection==NULL)
{
printf("connect error\n");
return ;
}
mysql_query(connection,"SET NAMES utf8");
char sql[]="insert into wchess(talks) values('%s')";
char sqlBuf[1024];
sprintf(sqlBuf,sql,str);
if(0!=mysql_query(connection,sqlBuf))
{
printf("operater error!!\n");
return ;
}
judge(str,mysql,connection);

mysql_close(connection);
}




/*********************************************************/
void deletesql(MYSQL *connection)
{
mysql_query(connection,"delete  from wchess");
}






/*******************************************************/
void judge(char *str,MYSQL mysql,MYSQL *connection)
{
MYSQL_RES *result;
MYSQL_ROW row;
if(result!=NULL)
   result=NULL;
char sqlBuf[]="select * from wchess where talks like '%棋%错%' or talks like '%棋%好%'";
if(0==mysql_query(connection,sqlBuf))
{
result=mysql_store_result(connection);
if(result!=NULL && NULL!=mysql_fetch_row(result))
{
str2="谢谢夸奖!";
deletesql(connection);
    if(result!=NULL)
       mysql_free_result(result);
return;
}
}


char sqlBuf1[]="select id from wchess where talks like '%离开%' or talks like '%再下%'";
if(0==mysql_query(connection,sqlBuf1))
{
result=mysql_store_result(connection);
if(result!=NULL && NULL!=mysql_fetch_row(result))
{
str2="好的，稍后继续!";
deletesql(connection);
    if(result!=NULL)
       mysql_free_result(result);
return;
}
}
char sqlBuf2[]="select id from wchess where talks like '%累%' or talks like '%下棋%'";
if(0==mysql_query(connection,sqlBuf2))
{
result=mysql_store_result(connection);
if(result!=NULL && NULL!=mysql_fetch_row(result))
{
str2="下下棋娱乐下吧!";
deletesql(connection);
    if(result!=NULL)
       mysql_free_result(result);
return;
}
}
char  sqlBuf3[]="select id from wchess where talks like '%休息%' or talks like '%睡觉%' or talks like '%不想玩%'";
if(0==mysql_query(connection,sqlBuf3))
{
result=mysql_store_result(connection);
if(result!=NULL && NULL!=mysql_fetch_row(result))
{
str2="好的，下次再战!";
deletesql(connection);
    if(result!=NULL)
       mysql_free_result(result);
return;
}
}
char sqlBuf4[]="select id from wchess where talks like '%天气%' or talks like '%太阳%'";
if(0==mysql_query(connection,sqlBuf4))
{
result=mysql_store_result(connection);
if(result!=NULL && NULL!=mysql_fetch_row(result))
{
str2="据气象台播报，今天明两天小雨.";
deletesql(connection);
    if(result!=NULL)
       mysql_free_result(result);
return;
}
}
char sqlBuf5[]="select id from wchess where talks like '%输了%' or talks like '%赢%'";
if(0==mysql_query(connection,sqlBuf5))
{
result=mysql_store_result(connection);
if(result!=NULL && NULL!=mysql_fetch_row(result))
{
str2="胜负乃兵家常事，我们下局再战。";
deletesql(connection);
    if(result!=NULL)
       mysql_free_result(result);
return;
}
}
char sqlBuf6[]="select id from wchess where talks like '%你%高兴%' or talks like '%你好%' or talks like '心情%不错' or talks like '%心情%'";
if(0==mysql_query(connection,sqlBuf6))
{
result=mysql_store_result(connection);
if(result!=NULL && NULL!=mysql_fetch_row(result))
{
str2="主人好，很高兴主人的召唤,主人想和我对弈吗？!";
deletesql(connection);
    if(result!=NULL)
       mysql_free_result(result);
return;
}
}
deletesql(connection);
str2="对不起，主人，这一句我无法回答，快点给我的大脑扩容啦，，";
}
















